﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq.Expressions;
using Newtonsoft.Json.Linq;

using CanDoo;
using CanDoo.Core;
using CanDoo.Data;
using CanDoo.Web;
using CanDoo.FineUI;
using CanDoo.Extensions;
using CanDoo.Oil.Core.Models;
using CanDoo.Oil.Core.Contracts;
using CanDoo.Admin.Core.Contracts;
using FineUIPro;

namespace CanDoo.Oil.WebApp.oilMoneyLog
{
    public partial class Edit : EditPagebase<IMoneyLogContract, MoneyLog>
    {
        public ICustomerContract CustomerContract { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (PageMode != pagemode.Add)
                    LoadData();
            }
        }

        protected override void LoadData(MoneyLog entity)
        {
            ed_Name.SetValue(entity.Name);
            ed_ChangeType.SetValue(entity.ChangeType);
            ed_LinkEntityId.SetValue(entity.LinkEntityId);
            ed_ChangeDirection.SetValue(entity.ChangeDirection);
            ed_MoneyBefore.SetValue(entity.MoneyBefore);
            ed_MoneyChanged.SetValue(entity.MoneyChanged);
            ed_MoneyNow.SetValue(entity.MoneyNow);
        }

        protected override OperationResult SaveData(MoneyLog entity)
        {
            entity.Name = ed_Name.GetValue().ToString();
            entity.ChangeType = ed_ChangeType.GetValue().ToInt();
            entity.LinkEntityId = ed_LinkEntityId.GetValue().ToLong();
            entity.ChangeDirection = ed_ChangeDirection.GetValue().ToInt();
            entity.MoneyBefore = ed_MoneyBefore.GetValue().ToDouble();
            entity.MoneyChanged = ed_MoneyChanged.GetValue().ToDouble();
            entity.MoneyNow = ed_MoneyNow.GetValue().ToDouble();
            return base.SaveData(entity);
            
        }
    }
}
